﻿Imports log4net
Module Main
    Dim logger As log4net.ILog = log4net.LogManager.GetLogger("Main")
    Sub Main()
            Dim jobEnum As New JobEnum
            Dim forceCopyTask = New ForceCopyTask
            Dim copyTask = New CopyTask
            Dim advanceTask = New AdvanceTask
            Dim adapJobList As New JobTableAdapters.JobListTableAdapter
            Dim adapJobHistory As New JobTableAdapters.JobHistoryTableAdapter
            Dim dtJobList As New Job.JobListDataTable
            Dim status As String
            Dim remark As String

            log4net.Config.XmlConfigurator.Configure()

            dtJobList = adapJobList.GetDataJobList()
            For Each rowIdR As Job.JobListRow In dtJobList
                status = jobEnum.JobStatus.Fail.ToString()
                remark = ""

                logger.Info("Start JOBID : " & rowIdR("JobId"))
                Dim jobHistory = adapJobHistory.InsertJobHistory(rowIdR("JobId"))

                Try
                    If rowIdR("JobName") = jobEnum.JobName.Force.ToString() Then
                        forceCopyTask.ForceCopy(rowIdR)
                    ElseIf rowIdR("JobName") = jobEnum.JobName.Copy.ToString() Then
                        copyTask.Copy(rowIdR)
                    ElseIf rowIdR("JobName") = jobEnum.JobName.Advance.ToString() Then
                        advanceTask.AdvanceCopy(rowIdR)
                    End If
                    status = jobEnum.JobStatus.Done.ToString()
                Catch ex As Exception
                    remark = ex.Message
                    logger.Error(ex.Message)
                    logger.Error(ex.StackTrace)
                End Try
                adapJobHistory.UpdateJobHistory(jobHistory)
                adapJobList.UpdateJobList(status, remark, rowIdR("JobId"))
                logger.Info("End JOBID : " & rowIdR("JobId"))
            Next
    End Sub
End Module
